package com.example.lee1.controller;

import com.example.lee1.entity.VideoCategoryEntity;
import com.example.lee1.service.VideoCategoryService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-13 16:12:03
 */
@RestController
@RequestMapping("generator/videocategory")
public class VideoCategoryController {
  @Autowired private VideoCategoryService videoCategoryService;

  /** 列表 */
  @RequestMapping("/list")
  @RequiresPermissions("generator:videocategory:list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = videoCategoryService.queryPage(params);

    return R.ok().put("page", page);
  }

  /** 信息 */
  @RequestMapping("/info/{videoId}")
  @RequiresPermissions("generator:videocategory:info")
  public R info(@PathVariable("videoId") Integer videoId) {
    VideoCategoryEntity videoCategory = videoCategoryService.getById(videoId);

    return R.ok().put("videoCategory", videoCategory);
  }

  /** 保存 */
  @RequestMapping("/save")
  @RequiresPermissions("generator:videocategory:save")
  public R save(@RequestBody VideoCategoryEntity videoCategory) {
    videoCategoryService.save(videoCategory);

    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  @RequiresPermissions("generator:videocategory:update")
  public R update(@RequestBody VideoCategoryEntity videoCategory) {
    videoCategoryService.updateById(videoCategory);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  @RequiresPermissions("generator:videocategory:delete")
  public R delete(@RequestBody Integer[] videoIds) {
    videoCategoryService.removeByIds(Arrays.asList(videoIds));

    return R.ok();
  }
}
